package cc.plumgo.j2me.utils;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

public abstract class CustomPage {
	protected int state;
	protected int selected;

	protected Sprite sprite;

	protected int scrWidth;
	protected int scrHeight;

	public CustomPage() {
		state = 0;
		selected = -1;
		scrWidth = CustomCanvas.canvas.getWidth();
		scrHeight = CustomCanvas.canvas.getHeight();
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	protected void loadSprite(String imgURI, int Width, int Height) {
		if (sprite == null) {
			try {
				Image img = Image.createImage(imgURI);
				sprite = new Sprite(img, Width, Height);

			} catch (Exception e) {
				e.printStackTrace();
			}
			sprite.defineReferencePixel(Width / 2, Height / 2);
			sprite.setFrame(0);
		}
	}

	protected void paint(Graphics g) {
		sprite.setPosition((scrWidth - sprite.getWidth()) / 2,
				(scrHeight - sprite.getHeight()) / 2);
		sprite.paint(g);
	}

	abstract public void process(int keyStates, Graphics g);
}
